#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2,re,os,xbmc

#author:
#elypter (elypter@yahoo.de)
#FreaX
#
#for details look at default.py
#version: 0.1
#date: 20100504 

def check(url):
	if url.rfind("filebase"):
		return 1
	else:
		return 0

def get_regexp():
	return "(http://filebase.to/files/[\d]*/[^/<>]*.avi)"
def get_name():
	return "filebase"
def join(id):
	return id
	
def get_link1(url):
	#takes an videopage-url of filebase
	#
	#returnes the service/mirror name, the url that will be passed over to get_link2, the url of the verification code
	
	BASE_PATH = os.getcwd().replace( ";", "" )
	BASE_DATA_PATH = os.path.join( xbmc.translatePath("special://profile/plugin_data/hoster"), "oracle2" )
	url = url.replace("filebase.to/files/", "filebase.to/download/")
	req = urllib2.Request(url)
	req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
	response = urllib2.urlopen(req)
	page=response.read()
	response.close()
	match=re.compile('http\://[^/<>"]*/download/ticket[^<>"]*.avi').findall(page)
	if len(match)>0:
		return ("got",match[0],'','','','','filebase')
		
def get_link2(param,code):
		return ("got",param,'','','','','filebase')